
const http = require('http')
const fs = require('fs')
const path = require('path')

http.createServer((req,res) => {

    //不同的路径返回不同的内容
    if(req.url == '/home' && req.method =='GET'){
        fs.readFile(path.join(__dirname,'hello.txt'),(err,data) => {
            res.end(data)
        })
    }else if(req.url == '/about' && req.method == 'GET'){
        fs.readFile(path.join(__dirname,'/about.txt'),(err,data) => {
            if(err) throw err;
            res.end(data)
        })
    }else{
        console.log('404  找不到资源')
    }


}).listen(8890,err => {
    if(err) throw err;
    console.log('server running at 8890端口')
})